package lty.pritace.topics;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;

/**
 * 持久化消息发送
 * 
 * @author lty
 *
 */
public class PersisternceSender {

	public static void main(String[] args) throws Exception {
		ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://192.168.233.128:61616");
		Connection connection = connectionFactory.createConnection();
		Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
		Destination destination = session.createTopic("topic2");
		MessageProducer producer = session.createProducer(destination);
		connection.start();
		producer.setDeliveryMode(DeliveryMode.PERSISTENT);
		for (int i = 0; i < 3; i++) {
			TextMessage message = session.createTextMessage("message333" + i);
			producer.send(message);
		}
		session.commit();
		session.close();
		connection.close();
	}
}
